﻿
using AutoMapper;
using ManagementApi.Models.Corp;
using Modules.Constructor;
using Modules.Corp;
using Modules.System.Area;
using PmSoft;

namespace ManagementApi.Models.Constructor
{
    public class ConstructorDto
    {
        /// <summary>
        /// 建设单位ID 
        ///</summary>
        public int ConstructorId { get; set; }
        /// <summary>
        /// 建设单位类型:个人、事业单位、政府机关、企业 
        ///</summary>
        public ConstructorType Type { get; set; }
        /// <summary>
        /// 建设单位类型名称
        /// </summary>
        public string TypeName { get; set; }
        /// <summary>
        /// 建设单位名称、个人姓名 
        ///</summary>
        public string Name { get; set; }
        /// <summary>
        /// 建设信用代码、身份证号码 
        ///</summary>
        public string Code { get; set; }
        /// <summary>
        /// 归属省代码 
        ///</summary>
        public int ProvinceCode { get; set; }
        /// <summary>
        /// 归属地市代码 
        ///</summary>
        public int CityCode { get; set; }
        /// <summary>
        /// 归属区县代码 
        ///</summary>
        public int AreaCode { get; set; }
        /// <summary>
        /// 归属地区名称
        /// </summary>
        public string AreaName { get; set; }
        /// <summary>
        /// 注册地址 
        ///</summary>
        public string RegAddr { get; set; }
        /// <summary>
        /// 办公地址 
        ///</summary>
        public string OfficeAddr { get; set; }
        /// <summary>
        /// 法人姓名 
        ///</summary>
        public string Legalman { get; set; }
        /// <summary>
        /// 法人身份证号码 
        ///</summary>
        public string LegalCardno { get; set; }
        /// <summary>
        /// 法人手机号码 
        ///</summary>
        public string LegalMobile { get; set; }
        /// <summary>
        /// 创建时间 
        /// 默认值: CURRENT_TIMESTAMP
        ///</summary>
        public DateTime CreateTime { get; set; }
    }

    public static partial class ConstructorExceptions
    {
        public static ConstructorDto AsDto(this ConstructorInfo constructor)
        {
            ConstructorDto dto = new ConstructorDto();
            dto.TypeName = constructor.Type.GetDescription();
            var areaService = ServiceAccessor.GetService<AreaService>();
            dto.AreaName = areaService.GetAreaFullName(constructor.ProvinceCode, constructor.CityCode, constructor.AreaCode);
            var mapper = ServiceAccessor.GetService<IMapper>();
            mapper.Map(constructor, dto);
            return dto;
        }
    }
}
